<template>
  <a-spin :loading="loading" style="width: 100%">
    <a-card
      class="general-card"
      :header-style="{ paddingBottom: '0' }"
      :body-style="{
        padding: '20px',
      }"
    >
      <template #title>
        小组链接分类占比
      </template>
      <Chart height="310px" :option="chartOption" />
    </a-card>
  </a-spin>
</template>

<script lang="ts" setup>
  import useLoading from '@/hooks/loading';
  import useChartOption from '@/hooks/chart-option';
  import { getBusinessLineData } from '@/api/dashboard/index';
  import { active } from 'sortablejs';
  import { ref } from 'vue';
  const businesslines = ref<string[]>([]);
  const totalH5Nums = ref<number>(0);
  const businesslineDataDetails = ref<object[]>([
   
  ]);
  const { loading } = useLoading();
  const { chartOption } = useChartOption((isDark) => {
    return {
      legend: {
        left: 'center',
        data: businesslines.value,
        bottom: 0,
        icon: 'circle',
        itemWidth: 8,
        textStyle: {
          color: isDark ? 'rgba(255, 255, 255, 0.7)' : '#4E5969',
        },
        itemStyle: {
          borderWidth: 0,
        },
      },
      tooltip: {
        show: true,
        trigger: 'item',
      },
      graphic: {
        elements: [
          {
            type: 'text',
            left: 'center',
            top: '40%',
            style: {
              text: '链接分类总量',
              textAlign: 'center',
              fill: isDark ? '#ffffffb3' : '#4E5969',
              fontSize: 14,
            },
          },
          {
            type: 'text',
            left: 'center',
            top: '50%',
            style: {
              text: totalH5Nums.value,
              textAlign: 'center',
              fill: isDark ? '#ffffffb3' : '#1D2129',
              fontSize: 16,
              fontWeight: 500,
            },
          },
        ],
      },
      series: [
        {
          type: 'pie',
          radius: ['50%', '70%'],
          center: ['50%', '50%'],
          label: {
            formatter: '{d}%',
            fontSize: 14,
            color: isDark ? 'rgba(255, 255, 255, 0.7)' : '#4E5969',
          },
          itemStyle: {
            borderColor: isDark ? '#232324' : '#fff',
            borderWidth: 1,
          },
          data: businesslineDataDetails.value,
        },
      ],
    };
  });
  const fetchData = async () => {
    let { data: chartData } = await getBusinessLineData();
    chartData.businesslineNames.filter((res) => {
      businesslines.value.push(res.businesslines);
    });
    chartData.businesslineDetails.filter((res) => {
      const item = {
        value: res.nums,
        name: res.businesslines,
      };
      businesslineDataDetails.value.push(item)
    });
    totalH5Nums.value = chartData.totalNums[0].nums || 0;
    console.log('过滤后的数据', businesslines.value);
  };
  fetchData();
</script>

<style scoped lang="less"></style>
